//
//  LSRegistrationCell.m
//  KuaiYi
//
//  Created by 袁应荣 on 2016/11/14.
//  Copyright © 2016年 HeiMa. All rights reserved.
//

#import "LSRegistrationCell.h"
#import <Masonry.h>
#import "UILabel+HMAddition.h"
#import "UIColor+HMAddition.h"
#import <UIImageView+WebCache.h>

@interface LSRegistrationCell ()

/* 图片视图 */
@property (weak, nonatomic) UIImageView *iconImageView;
/* 名字 */
@property (weak, nonatomic) UILabel *nameLabel;

@end
@implementation LSRegistrationCell

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self setupSubViews];
    }
    
    return self;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    [self setupSubViews];
}


- (void)setRegistration:(LSRegistrationModel *)registration
{
    _registration = registration;
    self.iconImageView.image = [UIImage imageNamed:_registration.icon];
    self.nameLabel.text = _registration.name;
}


- (void)setupSubViews
{
    // 创建子视图
    UIImageView *iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gy"]];
    
    [self.contentView addSubview:iconImageView];
    
    UILabel *nameLabel = [UILabel hm_labelWithText:@"🐼🐼" fontSize:26 color:[UIColor hm_colorWithHex:0x505050]];
    [self.contentView addSubview:nameLabel];
    
    // 自动布局
    CGSize iconSize = CGSizeMake(60, 60);
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(10);
        make.centerX.equalTo(self.contentView);
        make.size.mas_equalTo(iconSize);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView);
        make.top.equalTo(iconImageView.mas_bottom).offset(10);
    }];
    
    // 记录控件
    self.iconImageView = iconImageView;
    self.nameLabel = nameLabel;
}

@end
